home *** CD-ROM | disk | FTP | other *** search
- Path: jupiter.cs.uml.edu!jlee
- From: jlee@jupiter.cs.uml.edu (John Peter Lee)
- Newsgroups: comp.lang.c++
- Subject: when to inherit, when to compose...
- Date: 26 Mar 1996 15:56:41 GMT
- Organization: UMass-Lowell Computer Science
- Message-ID: <4j943p$7es@ulowell.uml.edu>
- NNTP-Posting-Host: jupiter.cs.uml.edu
-
- Hi:
-
- I'm wondering about an OO design. Under what circumstances is it more
- advantageous to use an inheritance hierarchy for a design, as opposed
- to using object containment, and vice versa?
-
- With object containment: class "A" has a member class "B" declared
- within it. A acts as a kindof handle class (I think) that forwards
- requests to B, and handles B's output.
-
- With inheritance: class "A" is a base class, and class "B" is a derived
- class. Then A has virtual functions that are implemented in B.
-
- -> Are there any general rules of thumb to apply here? Any literature?
-
-
- The design I am currently developing involves classes that are graphical
- in nature - they have a lot of Motif and graphics-related info. I want to
- shield all of this graphics stuff from certain objects that interact with
- these classes in a non-graphical way (I'm placing graphics descriptors
- into a type of history structure, and doing a lot of manipulations of
- these descriptors - actual graphics isn't required for any of this stuff).
- I'm wondering whether or not to shield things via containment by having
- a graphical class ptr as a member of the base class, or via inheritance by
- having a subclass inherit the graphical stuff from a graphical base class.
-
- thanks in advance - please reply directly to me.
-
- jp
-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- JP Lee Institute for Visualization and Perception Research
- jlee@cs.uml.edu University of Massachusetts at Lowell
- (508) 934-3384 1 University Ave. Lowell, MA 01854
- (508) 452-4298 fax
-
- Don't accept cheap imitations !!!!
-
- Support H.R. 1500 - America's Redrock Wilderness Act !
-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-